home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / tutor.swg / 0014_Data representation; reading spec sheets.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-11-28  |  25.8 KB  |  688 lines

  1.                         Turbo Pascal for DOS Tutorial
  2.                              by Glenn Grotzinger
  3.             Part 11 -- data representation; reading specs sheets
  4.                   copyright (c) 1995-96 by Glenn Grotzinger
  5.  
  6. Is there still any interest in this tutorial?  If so, tell me! :>
  7.  
  8. Here is a solution to last chapter's problem.  Here is the unit.
  9.  
  10. UNIT10
  11.  
  12. {$O+}
  13. unit unit10;
  14.  
  15. interface
  16.   uses dos;
  17.   function parse_filespec(filename: string):string;
  18.   procedure copyafile(inname, outname: string);
  19.   procedure writehelp;
  20.   procedure process;
  21.  
  22. implementation
  23.  
  24. function parse_filespec(filename: string):string;
  25.     const
  26.       all_files = $27;
  27.     var
  28.       dir: dirstr;
  29.       name: namestr;
  30.       ext: extstr;
  31.       attr: word;
  32.       f: text;
  33.     begin
  34.       filename := fexpand(filename);
  35.       if filename[length(filename)] <> '\' then
  36.         begin
  37.           assign(f, filename);
  38.           getfattr(f, attr);
  39.           if (doserror = 0) and (attr and $10 > 0) then
  40.             filename := filename + '\';
  41.         end;
  42.       fsplit(filename, dir, name, ext);
  43.       if name = '' then name := '*';
  44.       if ext = '' then ext := '.*';
  45.       parse_filespec := dir+name+ext;
  46.     end;
  47.  
  48.   procedure copyafile(inname, outname: string);
  49.     var
  50.       infile, outfile: file;
  51.       buffer: array[1..8192] of byte;
  52.       bytesw, bytesr: integer;
  53.       time: longint;
  54.       attribute: word;
  55.  
  56.     begin
  57.       assign(infile, inname);
  58.       getfattr(infile, attribute);
  59.       reset(infile, 1);
  60.       write('Copying ', inname, ' (', filesize(infile), ' bytes)...');
  61.       assign(outfile, outname);
  62.       setfattr(outfile, attribute);
  63.       rewrite(outfile, 1);
  64.       repeat
  65.         blockread(infile, buffer, sizeof(buffer), bytesr);
  66.         if bytesr > 0 then
  67.           blockwrite(outfile, buffer, bytesr, bytesw);
  68.       until bytesr = 0;
  69.       getftime(infile, time);
  70.       setftime(outfile, time);
  71.       close(infile);
  72.       close(outfile);
  73.       writeln('done...');
  74.     end;
  75.  
  76.   procedure writehelp;
  77.     begin
  78.       writeln('Provide a source and a destination.');
  79.       halt(1);
  80.     end;
  81.  
  82.   procedure process;
  83.     begin
  84.       if paramcount <> 2 then
  85.         writehelp;
  86.       copyafile(parse_filespec(paramstr(1)), parse_filespec(paramstr(2)));
  87.     end;
  88.  
  89. end.
  90. And here is the main program
  91.  
  92. program part10; uses unit10, overlay;
  93.  
  94.  
  95.   {$O UNIT10.TPU}
  96.  
  97.  
  98.   begin
  99.     ovrinit('PART10.OVR');
  100.     if OvrResult <> 0 then
  101.       begin
  102.         case OvrResult of
  103.           -1: writeln('Overlay manager error.');
  104.           -2: writeln('Overlay file not found.');
  105.           -3: writeln('Not enough memory for Overlay Buffer.');
  106.           -4: writeln('Overlay I/O error.');
  107.         end;
  108.         halt(1);
  109.       end;
  110.     OvrInitEMS;
  111.     case OvrResult of
  112.       0: writeln('Overlay loaded to EMS memory!');
  113.      -5: writeln('No EMS driver found! Loading to conventional.');
  114.      -6: writeln('Not enough EMS memory!');
  115.     end;
  116.     process;
  117.   end.
  118.  
  119.  
  120. Basically, the plan for this tutorial is to go through all standard data
  121. types and show how TP stores them in memory, so we will be able to interpret
  122. a binary data file we may create.  Then, using the information we presented
  123. on how things are stored, we will get a spec sheet on a common format, and
  124. interpret the data, so we may be able to obtain data from that file through
  125. a Pascal program.
  126.  
  127. Byte
  128. ====
  129. The basic idea of a byte has been covered in part 7 of the tutorial.
  130. Please refer back to there for a refresher on the concept of what a byte is.
  131.  
  132. Basically, a byte can be used to substitute or represent a char type,
  133. or a number type....The number types, stored as a byte, have a limit of
  134. 0..255 as an unsigned number (byte), and -128..127 with a signed number
  135. (shortint).  The terms in the parentheses are what we would define the
  136. byte to be to get the specified range.  I will explain later in this
  137. tutorial the difference between a "signed" and "unsigned" number, actually
  138. signed and unsigned data space for numbers.
  139.  
  140. The number for an unsigned number is formed, much like we were doing the
  141. binary computations in part 7.
  142.  
  143. Numbers as Integers
  144. ===================
  145. There are several types of numbers we can define...
  146.  
  147. Byte, and ShortInt: as described above in the byte description...
  148.  
  149. Integer types are either as signed (range: -32768..32767) or unsigned
  150. (0..65535) words.  A word is a unit of 2 bytes in TP.  Basically, in
  151. a unsigned integer, the number is calculated from right to left in binary
  152. much like a byte.  Since it is easier, for us to show binary storage
  153. repsentation as hexadecimal units of bytes, we will use hexadecimal values
  154. for an example.
  155.  
  156. An integer type is written to disk, to test something.  The sequence of
  157. two bytes is:  3F 4D  .  What is the number in base 10 form?
  158.  
  159. If we remember from our hex notation, and the way things work:
  160.  
  161.    3 * 16^3 + 15 * 16^2 + 4 * 16^1 + 13 * 16^0 = 16205
  162.  
  163. An integer is ALWAYS two bytes, whether or not the number may technically
  164. fill two bytes in this manner described before.  For example, 13 in base
  165. 10 is stored in memory and on disk by TP in integer form as 00 0D .  We
  166. could equally store this number as a byte if we knew that this variable
  167. location would never be requested to hold a number that is greater than
  168. 255.  For example, if we knew we were going to hold days of the month
  169. in memory, we would never have a number greater than 31, so a byte type
  170. for this number would be appropriate.
  171.  
  172. A longint type is always a signed number, but we do need to know, that
  173. it is what is called a double word, or two words put together.  Therefore,
  174. we know that a longint type is 4 bytes, and has a maximum limit of 2bil.
  175. A longint is ALWAYS 4 bytes, whether or not the number may fill 4 bytes.
  176. 13 in base 10 would be stored in a longint as 00 00 00 0D .
  177.  
  178. Char
  179. ====
  180. A character is stored in memory as a byte, with the byte value
  181. representing the corresponding character as it refers to the
  182. ASCII chart.
  183.  
  184. byte representation 67 as a char is C.
  185.  
  186. Signed vs. Unsigned Integer Numbers
  187. ===================================
  188. We have talked before in this part about signed and unsigned numbers.  In
  189. part 7, essentially, we have covered unsigned numbers, when we were
  190. describing binary logic.  Let's describe what a signed number is.
  191.  
  192. A signed number is represented by either using a base system of 0..1, or
  193. 1..0 in binary.  In a signed number, the leftmost bit is either 0 for a
  194. positive number, and 1 for a negative number.  For positive numbers, the
  195. remaining bits are considered using a 0..1 scheme as we did in part 7
  196. with the binary computations.  For a negative number, we count starting
  197. from 1 and go down to 0.
  198.  
  199. Let's observe what that difference is, by demonstrating how 3 and -3 would
  200. be shown in a shortint (signed) type in binary.
  201.  
  202. Let's start with 3 in binary as a signed number. That is a positive number
  203. so the leftmost bit will be 0.  Then we will use a 0..1 counting system
  204. to finish out the number using standard binary notation.  So, 3 will be
  205. represented in a shortint value as:
  206.  
  207.                              0000     0010 
  208.  
  209. just like it was an unsigned number.  Now, lets observe what -3 would look
  210. like.  That is a negative number, so the leftmost bit would be a 1.  Since
  211. we use a 1..0 system, we would start with 1's in everything.  We know 3 is
  212. 10 in binary, so we use a reverse system and come up with:
  213.  
  214.                              1111     1101
  215.  
  216. To illustrate further, in binary counting (to a computer) -1..-5 would be
  217. (represented in hex) as $FF,$FE,$FD,$FC,$FB; as opposed to $01,$02,$03,
  218. $04,$05 for 1..5 .  In a signed system, negative number counting starts at
  219. -1, which explains why the equal range of a shortint is -128..127, and
  220. there are equally 128 items (positive and negative).
  221.  
  222. As practice, look at the integers.dat now, in a hex viewer, and see exactly
  223. how the numbers are stored.  They are two bytes in length, and should count
  224. from one to ten, as we did in the program.  It should look like this in
  225. your hex viewer....
  226.  
  227. 00 01 00 02 00 03 00 04 00 05 00 06 00 07 00 08 00 09 00 0A
  228.  
  229. I recommend very heavily that you get a hex viewer to be able to help out.
  230.  
  231. Boolean
  232. =======
  233. 0 = False; 1 = True
  234.  
  235. Common Pascal Strings
  236. =====================
  237. Now we will start to discuss the format of grouped data.  The first format
  238. we will discuss will be the common pascal string.  The format of a pascal
  239. string formatted group of characters is the following.
  240.  
  241. When we define a string without a subscript, we are defining a maximum of
  242. 255 characters. When we define for example, a string[20], we are defining
  243. a max of 20 characters.  In reality, we are defining the number of char-
  244. acters + 1.  A string has a first byte (0th byte) that represents the
  245. actual character length of the data stored in the string, as an unsigned
  246. byte. (Actually, the length function reads this byte when you call it,
  247. but it's also possible to read and refer to the byte, and even SET it.)
  248.  
  249. Refer back to part 8 where I said you could individually set each part
  250. of the string.  It's possible to actually build a string by setting the
  251. length byte, then setting the rest of the string as characters.  Say,
  252. to set the dynamic length of a string to 4, we can do this, as in this
  253. example, which will only write "Hello" instead of "Hello world!".  We
  254. are setting the 0'th part of the string as a character, which we need
  255. to do:
  256.  
  257. program test; 
  258.   var
  259.     p: string;
  260.   begin
  261.     p := 'Hello world!';
  262.     p[0] := #5;
  263.     writeln(p);
  264.   end.
  265.  
  266. Blocked Character Strings
  267. =========================
  268. It's also possible to work with an array of characters as a string, by
  269. referring to the whole array.  The maximum length must be set by the
  270. length of the array, essentially.
  271.  
  272. str: array[1..20] of char;
  273.  
  274. if we read this structure in as a whole, it will have 20 characters in it,
  275. in which we can write back out to the screen by saying WRITE(STR);, or
  276. actually convert to a string by counting through to find the actual length
  277. and then setting the length byte.
  278.  
  279. Null Terminated Strings
  280. =======================
  281. This is a length of characters, which are terminated by a null character,
  282. or #0.  The strings unit is documented to work with these strings, but it's
  283. easier to get away with simply converting it into something we can work
  284. with through Pascal itself, if we have to do much with it.
  285.  
  286. Arrays
  287. ======
  288. The general structure of an array was described in part 6.  It is basically
  289. usable as a grouping of items.
  290.  
  291. Records
  292. =======
  293. A record is stored in memory basically as a grouping of data types.  The
  294. record type below:
  295.  
  296.   datarecord = record
  297.     int: integer;
  298.     character: char;
  299.   end;
  300.  
  301. would be stored in memory like this:
  302.  
  303.  INT CHARACTER
  304.  
  305.  
  306. Now, we have described all of the pertinent items we need to know to be
  307. able to work through a spec sheet on a common format.  Basically, data
  308. for spec sheets are sometimes presented as the record format, in either
  309. Pascal or C format.  We don't need to really do any work for that, but
  310. most of the time, it will be presented in a byte by byte offset format.
  311.  
  312. Let us look at this structure file for an example.  It is of the standard
  313. sound file called a MOD file. (you can find them anywhere, almost)  We
  314. will cover just the header of the file for now...
  315. -------------------------------------------------------------------------
  316.  
  317. Protracker 1.1B Song/Module Format:
  318.  
  319. Offset  Bytes  Description
  320.    0     20    Songname. Remember to put trailing null bytes at the end...
  321.  
  322. Information for sample 1-31:
  323.  
  324. Offset  Bytes  Description
  325.   20     22    Samplename for sample 1. Pad with null bytes.
  326.   42      2    Samplelength for sample 1. Stored as number of words.
  327.                Multiply by two to get real sample length in bytes.
  328.   44      1    Lower four bits are the finetune value, stored as a signed
  329.                four bit number. The upper four bits are not used, and
  330.                should be set to zero.
  331.                Value:  Finetune:
  332.                  0        0
  333.                  1       +1
  334.                  2       +2
  335.                  3       +3
  336.                  4       +4
  337.                  5       +5
  338.                  6       +6
  339.                  7       +7
  340.                  8       -8
  341.                  9       -7
  342.                  A       -6
  343.                  B       -5
  344.                  C       -4
  345.                  D       -3
  346.                  E       -2
  347.                  F       -1
  348.  
  349.   45      1    Volume for sample 1. Range is $00-$40, or 0-64 decimal.
  350.   46      2    Repeat point for sample 1. Stored as number of words offset
  351.                from start of sample. Multiply by two to get offset in bytes.
  352.   48      2    Repeat Length for sample 1. Stored as number of words in
  353.                loop. Multiply by two to get replen in bytes.
  354.  
  355. Information for the next 30 samples starts here. It's just like the info for
  356. sample 1.
  357.  
  358. Offset  Bytes  Description
  359.   50     30    Sample 2...
  360.   80     30    Sample 3...
  361.    .
  362.    .
  363.    .
  364.  890     30    Sample 30...
  365.  920     30    Sample 31...
  366.  
  367. Offset  Bytes  Description
  368.  950      1    Songlength. Range is 1-128.
  369.  951      1    Well... this little byte here is set to 127, so that old
  370.                trackers will search through all patterns when loading.
  371.                Noisetracker uses this byte for restart, but we don't.
  372.  952    128    Song positions 0-127. Each hold a number from 0-63 that
  373.                tells the tracker what pattern to play at that position.
  374. 1080      4    The four letters "M.K." - This is something Mahoney & Kaktus
  375.                inserted when they increased the number of samples from
  376.                15 to 31. If it's not there, the module/song uses 15 samples
  377.                or the text has been removed to make the module harder to
  378.                rip. Startrekker puts "FLT4" or "FLT8" there instead.
  379.  
  380. Source: Lars "ZAP" Hamre/Amiga Freelancers
  381.  
  382. --------------------------------------------------------------------------
  383.  
  384. Building the basic record format
  385. ================================
  386. We will need to essentially, for any standard file, built record format(s)
  387. for the file.  Let us start with this one.
  388.  
  389. It says above that the first 20 bytes would be a song title.  The description
  390. best seems to define it as a null-terminated string, but we know the maximum
  391. limit.  So, lets just call it a blocked character string of length 20.  So
  392. we will use this description for part of our component record:
  393.  
  394. songname: array[1..20] of char;
  395.  
  396. If we read on through the file, it states data for samples 1-31.  They are
  397. varied data, so that infers that we need to build another record format.
  398. But for the position so far in our current record format, we will use
  399. this, since we know that there are a group of 31 samples...we will call
  400. our alternate record for the sample data, samplerec.
  401.  
  402. sampledata: array[1..31] of samplerec;
  403.  
  404. Alternate Sample Record
  405. =======================
  406. 22 bytes are defined for a samplename.  Same logic for songname.  So this
  407. unit of our sample record will be
  408.  
  409. samplename: array[1..22] of char;
  410.  
  411. The next part is a sample length defined by 2 bytes.  So, we could either
  412. call this a word, or an integer:
  413.  
  414. samplelength: integer;
  415.  
  416. One byte for a finetune value.  Logical definition:
  417.  
  418. finetune: byte;
  419.  
  420. Volume is defined as one byte.  So...
  421.  
  422. volume: byte;
  423.  
  424. Repeat point and Repeat length are both defined as words above so...
  425.  
  426. repeatpoint: integer;
  427. repeatlength: integer;
  428.  
  429. It is indicated above that we are done with the samples.  Therefore, our
  430. final record format for the samples would be:
  431.  
  432. samplerec = record
  433.   samplename: array[1..22] of char;
  434.   samplelength: integer;
  435.   finetune: byte;
  436.   volume: byte;
  437.   repeatpoint: integer;
  438.   repeatlength: integer;
  439. end;
  440.  
  441. Finishing the Record Format
  442. ===========================
  443. Continuing on...
  444.  
  445. songlength is a byte.  So
  446.  
  447. songlength: byte;
  448.  
  449. A byte is defined next that seems like a filler byte.  So...
  450.  
  451. filler: byte;
  452.  
  453. The next set of 128 bytes are defined as "song positions 0-127".  Each byte
  454. is also defined to hold a number, so lets keep to that:
  455.  
  456. positions: array[0..127] of byte;
  457.  
  458. The next 4 bytes to finish out our headers is the moduleid.  it's 4 bytes,
  459. text, so...
  460.  
  461. id: array[1..4] of char;
  462.  
  463. Having gone through the header format for this file, we have come up with
  464. a record we can use to read all the header data, that we would need to read
  465. for a mod file.  Therefore, we can use a final type listing in our program
  466. to read a mod file header of:
  467.  
  468. samplerec = record
  469.   samplename: array[1..22] of char;
  470.   samplelength: integer;
  471.   finetune: byte;
  472.   volume: byte;
  473.   repeatpoint: integer;
  474.   repeatlength: integer;
  475. end;
  476.  
  477. modrecord = record
  478.   songname: array[1..20] of char;
  479.   sampledata: array[1..31] of samplerec;
  480.   songlength: byte;
  481.   filler: byte;
  482.   positions: array[0..127] of byte;
  483.   id: array[1..4] of char;
  484. end;
  485.  
  486. We can use this format to gain any information we know about a file.  To
  487. test this format, we need to write a program that pulls the information
  488. out of a standard file, that we know, and check to see if they're identical.
  489. For MODs, we would need to get a player, and load up the player, in order
  490. to get data we are familiar with from the spec sheet, such as the id being
  491. "M.K.".
  492.  
  493. All the data we need to know to extract data out, and get formatted data
  494. from standards files, have been presented.
  495.  
  496. Practice Programming Problem #11
  497. ================================
  498. In keeping with the topic of this tutorial, I am asking you to write a
  499. program entirely in Pascal that will take a ZIP file name from the command-
  500. line and then print a list of all the files within that zip file.  With
  501. each filename, list the compressed size, uncompressed size, date, time,
  502. and compression method, one per file.  At the end, list the total number
  503. of files, total compressed and uncompressed size, effective compression
  504. ratio, and write the comment. Then output this list to a file taken on
  505. the command-line.  For example, a command-line will always be:
  506.  
  507. ZIPLIST FILENAME.ZIP OUTPUT.TXT
  508.  
  509. Be sure to design this program with any error checks you may need to perform.
  510. Don't forget to devise a check to be sure you are dealing with a ZIP file
  511. on the first parameter.  Here, we have gone to look at some references,
  512. and have found the following out of a specs list:
  513.  
  514. --------A-ZIP-------------------------------
  515. The ZIP archives are created by the PkZIP/PkUnZIP combo produced
  516. by the PkWare company. The PkZIP programs have with LHArc and ARJ
  517. the best compression.
  518. The directory information is stored at the end of the archive, each local
  519. file in the archive begins with the following header; This header can be used
  520. to identify a ZIP file as such :
  521. OFFSET              Count TYPE   Description
  522. 0000h                   4 char   ID='PK',03,04
  523. 0004h                   1 word   Version needed to extract archive
  524. 0006h                   1 word   General purpose bit field (bit mapped)
  525.                                       0 - file is encrypted
  526.                                       1 - 8K/4K sliding dictionary used
  527.                                       2 - 3/2 Shannon-Fano trees were used
  528.                                     3-4 - unused
  529.                                    5-15 - used internally by ZIP
  530.                                  Note:  Bits 1 and 2 are undefined if the
  531.                                         compression method is other than
  532.                                         type 6 (Imploding).
  533. 0008h                   1 word   Compression method (see table 0010)
  534. 000Ah                   1 dword  Original DOS file date/time (see table 0009)
  535. 000Eh                   1 dword  32-bit CRC of file (inverse??)
  536. 0012h                   1 dword  Compressed file size
  537. 0016h                   1 dword  Uncompressed file size
  538. 001Ah                   1 word   Length of filename
  539.                                  ="LEN"
  540. 001Ch                   1 word   Length of extra field
  541.                                  ="XLN"
  542. 001Eh               "LEN" char   path/filename
  543. 001Eh               "XLN" char   extra field
  544. +"LEN"
  545. After all the files, there comes the central directory structure.
  546.  
  547. (Table 0009)
  548. Format of the MS-DOS time stamp (32-bit)
  549. The MS-DOS time stamp is limited to an even count of seconds, since the
  550. count for seconds is only 5 bits wide.
  551.  
  552.   31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
  553.  |<---- year-1980 --->|<- month ->|<--- day ---->|
  554.  
  555.   15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
  556.  |<--- hour --->|<---- minute --->|<- second/2 ->|
  557.  
  558. (Table 0010)
  559. PkZip compression types
  560. 0 - Stored / No compression
  561. 1 - Shrunk / LZW, 8K buffer, 9-13 bits with partial clearing
  562. 2 - Reduced-1 / Probalistic compression, lower 7 bits
  563. 3 - Reduced-2 / Probalistic compression, lower 6 bits
  564. 4 - Reduced-3 / Probalistic compression, lower 5 bits
  565. 5 - Reduced-4 / Probalistic compression, lower 4 bits
  566. 6 - Imploded / 2/3 Shanno-Fano trees, 4K/8K sliding dictionary
  567. [7..9 also exist] => note added by Glenn Grotzinger from Phil Katz's
  568. description
  569.  
  570. --- Central directory structure
  571. The CDS is at the end of the archive and contains additional information
  572. about the files stored within the archive.
  573. OFFSET              Count TYPE   Description
  574. 0000h                   4 char   ID='PK',01,02
  575. 0004h                   1 byte   Version made by
  576. 0005h                   1 byte   Host OS (see table 0011)
  577. 0006h                   1 byte   Minimum version needed to extract
  578. 0007h                   1 byte   Target OS
  579.                                  see above "Host OS"
  580. 0008h                   1 word   General purpose bit flag
  581.                                  see above "General purpose bit flag"
  582. 000Ah                   1 word   Compression method
  583.                                  see above "Compression method"
  584. 000Ch                   1 dword  DOS date / time of file (see table 0009)
  585. 0010h                   1 dword  32-bit CRC of file 
  586. 0014h                   1 dword  Compressed size of file
  587. 0018h                   1 dword  Uncompressed size of file
  588. 001Ch                   1 word   Length of filename
  589.                                  ="LEN"
  590. 001Eh                   1 word   Length of extra field
  591.                                  ="XLN"
  592. 0020h                   1 word   Length of file comment
  593.                                  ="CMT"
  594. 0022h                   1 word   Disk number ??
  595. 0024h                   1 word   Internal file attributes (bit mapped)
  596.                                     0 - file is apparently an ASCII/binary file
  597.                                  1-15 - unused
  598. 0026h                   1 dword  External file attributes (OS dependent)
  599. 002Ah                   1 dword  Relative offset of local header from the
  600.                                  start of the first disk this file appears on
  601. 002Eh               "LEN" char   Filename / path; should not contain a drive
  602.                                  or device letter, all slashes should be forward
  603.                                  slashes '/'.
  604. 002Eh+              "XLN" char   Extra field
  605. +"LEN"
  606. 002Eh               "CMT" char   File comment
  607. +"LEN"
  608. +"XLN"
  609.  
  610. (Table 0011)
  611. PkZip Host OS table
  612. 0 - MS-DOS and OS/2 (FAT)
  613. 1 - Amiga
  614. 2 - VMS
  615. 3 - *nix
  616. 4 - VM/CMS
  617. 5 - Atari ST
  618. 6 - OS/2 1.2 extended file sys
  619. 7 - Macintosh
  620. 8-255 - unused
  621.  
  622. --- End of central directory structure
  623. The End of Central Directory Structure header has following format :
  624. OFFSET              Count TYPE   Description
  625. 0000h                   4 char   ID='PK',05,06
  626. 0004h                   1 word   Number of this disk
  627. 0006h                   1 word   Number of disk with start of central directory
  628. 0008h                   1 word   Total number of file/path entries on this disk
  629. 000Ah                   1 word   Total number of entries in central dir
  630. 000Ch                   1 dword  Size of central directory
  631. 0010h                   1 dword  Offset of start of central directory relative
  632.                                  to starting disk number
  633. 0014h                   1 word   Archive comment length
  634.                                  ="CML"
  635. 0016h               "CML" char   Zip file comment
  636.  
  637. EXTENSION:ZIP
  638. OCCURENCES:PC,Amiga,ST
  639. PROGRAMS:PkZIP,WinZIP
  640. REFERENCE:Technote.APP
  641.  
  642. Source: FILEFMTS (c) 1994,1995 Max Maischein
  643.  
  644.  
  645. Sample output for this program
  646. ==============================
  647.  
  648.                        Files contained in FILENAME.ZIP
  649.  
  650. NAME         COMP-SIZE     DATE     TIME     UNCOMP-SIZE  COMP-METHOD       
  651. ---------------------------------------------------------------------
  652. FOOBAR10.TXT       732  10-01-1993  02:30          1021       7
  653.  FOBAR11.ZIP     11021  12-01-1995  22:03         23923       6
  654. ...
  655. ---------------------------------------------------------------------
  656.                1520032                          4023232
  657.  
  658. 15 files; Effective compression ratio: 65.3%
  659.  
  660. < write the comment here, or write "No ZIP comment." if there is no
  661. ZIP comment >
  662.  
  663.  
  664. Notes:
  665. 1) Note how I have the sample output.  It needs to be EXACTLY as I have
  666. listed it.
  667. 2) The orders and the methods you need to use to read files should be
  668. evident from the specs file.  They will be random reads...
  669. 3) With the random reads, it is about impossible to tell what you got
  670. read unless you check first...Notice a good way to check out of the
  671. first field of each record...
  672. 4) The "MS-DOS Time Format" can be done really easily.  Just think DOS
  673. unit.
  674. 5) Do not read anything unless you HAVE to....
  675. 6) Since this is a program that happens to use another program's data,
  676. more than likely, the data are correct, so there is no need to check
  677. any of the data beyond determining whether it's an actual ZIP file.
  678.  
  679. With this data listed, you should be able to do anything related to listing,
  680. stripping comments, showing comments, and so on and so forth.
  681.  
  682. Next Time
  683. =========
  684. We will cover the use of stacks and queues.  Send any comments,
  685. encouragements, problems, etc, etc. to ggrotz@2sprint.net.  Haven't
  686. seen anything of that type, ya know....
  687.  
  688.